# -*- coding: utf-8 -*-
# Assertion utilities for encryption and signing based on PKCS#1 v1.5
# See http://www.di-mgt.com.au/rsa_alg.html#pkcs1schemes
"""Assertion utilities for encryption and signing based on PKCS#1 v1.5.
See http://www.di-mgt.com.au/rsa_alg.html#pkcs1schemes

NOTICE: This program is used for learning, there may have bugs
and potential security issues. Please DO NOT use this program
in production environment.

WARNING: Do not pass any Python traceback information to users
for it may leaks the type and the position of a failure when
it occurred.
"""

__author__ = 'Kainan Zhu'
__email__ = 'dlangu0393@gmail.com'
__copyright__ = 'Copyright 2013, Kainan Zhu'

from rsa.key import RSAKey, PrivateKey, PublicKey


def param_assert_str(value, param):
    if not isinstance(value, str):
        raise TypeError('Param %s should be a string of bytes, %s got' % (param, value.__class__))


def param_assert_private_key(value, param):
    if not isinstance(value, PrivateKey):
        raise TypeError('Param %s should be PrivateKey, %s got' % (param, value.__class__))


def param_assert_public_key(value, param):
    if not isinstance(value, PublicKey):
        raise TypeError('Param %s should be PublicKey, %s got' % (param, value.__class__))


def param_assert_key(value, param):
    if not isinstance(value, RSAKey):
        raise TypeError('Param %s should be PublicKey or PrivateKey, %s got' % (param, value.__class__))


def param_assert_int(value, param):
    if not isinstance(value, (int, long)):
        raise TypeError('Param %s should be an integer, %s got' % (param, value.__class__))